package com.ylbh.modules.commentstar.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.Ref;
import com.ylbh.common.utils.ShiroUtils;
import com.ylbh.modules.commentstar.entity.ShoppingCommentStar;
import com.ylbh.modules.commentstar.service.ShoppingCommentStarService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.common.utils.PageUtils;

/**
 * 评价星级信息模板
 *
 * @author czx
 * @date 2019-08-21 14:11:52
 */
@RestController
@RequestMapping("comment/star")
public class ShoppingCommentStarController {
    @Autowired
    private ShoppingCommentStarService shoppingCommentStarService;

    @ApiOperation("获取评价模板列表")
    @GetMapping("/queryCommentStarList")
    @RequiresPermissions("comment:star:queryCommentStarList")
    public CommonResult<PageUtils> queryCommentStarList(@RequestParam Map<String, Object> params){
        PageUtils page = shoppingCommentStarService.queryCommentStarList(params);
        return Ref.ok(page);
    }

    @ApiOperation("获取评价模板详情")
    @GetMapping("/getCommentStarDetailsById/{starId}")
    @RequiresPermissions("comment:star:getCommentStarDetailsById")
    public CommonResult<ShoppingCommentStar> getCommentStarDetailsById(@PathVariable("starId") Integer starId){
		ShoppingCommentStar shoppingCommentStar = shoppingCommentStarService.getById(starId);
        return Ref.ok(shoppingCommentStar);
    }

    @SysLog("添加评价模板信息")
    @ApiOperation("添加评价模板信息")
    @PostMapping("/addCommentStar")
    @RequiresPermissions("comment:star:addCommentStar")
    public CommonResult addCommentStar(@RequestBody ShoppingCommentStar shoppingCommentStar){
        shoppingCommentStar.setCreateTime(new Date());
        shoppingCommentStar.setCreateUserId(ShiroUtils.getUserId().intValue());
		shoppingCommentStarService.save(shoppingCommentStar);
        return Ref.ok();
    }

    @SysLog("修改评价模板信息")
    @ApiOperation("修改评价模板信息")
    @PostMapping("/modifyCommentStarById")
    @RequiresPermissions("comment:star:modifyCommentStarById")
    public CommonResult modifyCommentStarById(@RequestBody ShoppingCommentStar shoppingCommentStar){
        shoppingCommentStar.setCreateTime(new Date());
        shoppingCommentStar.setCreateUserId(ShiroUtils.getUserId().intValue());
		shoppingCommentStarService.updateById(shoppingCommentStar);
        return Ref.ok();
    }

    @SysLog("删除评价模板信息")
    @ApiOperation("删除评价模板信息")
    @PostMapping("/removeCommentStarById")
    @RequiresPermissions("comment:star:removeCommentStarById")
    public CommonResult removeCommentStarById(@RequestBody Integer[] starIds){
		String msg = shoppingCommentStarService.removeCommentStarById(Arrays.asList(starIds));
        return Ref.ok(msg);
    }

    @ApiOperation("根据星级查询")
    @GetMapping("/queryStarList/{starClass}")
    public CommonResult queryStarList(@PathVariable Integer starClass) {
        List<ShoppingCommentStar> list = shoppingCommentStarService.queryStarList(starClass);
        return Ref.ok(list);
    }

}
